/*============================================================================*/
/*                   CONTINENTAL AUTOMOTIVE SYSTEMS                           */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* name:            HAL_led.c
* version:         1.0
* created_by:      Continental
* date_created:    June 7 2013
*=============================================================================*/
/* DESCRIPTION : Source file for abstraction layer for LED                    */
/*============================================================================*/
/* FUNCTION COMMENT : Source file abstraction layer for LED                   */
/*                                                                            */
/*============================================================================*/
/*                               OBJECT HISTORY                               */
/*============================================================================*/
/*  REVISION |   DATE      |                               |      AUTHOR      */
/*----------------------------------------------------------------------------*/
/*  1.0      | 07/jun/2013 |                               | Continental      */
/* Initial version for the Lab 2 using Freescale Bolero micro.                */
/*============================================================================*/

#include "sysinit.h"
#include "HAL_led.h"

#include "MAL_ioapi.h"
#include "MAL_pwm.h"


/****************************************************************************************************/
/**
* \brief    Configures individual GPIO pins to either input or output functionality.  
* \author   Abraham Tezmol
* \param    T_UBYTE channel - GPIO channel to be configured
* \param    T_UBYTE input_output - selection of input/output functionality (has impact on output impedance selection)
* \param    T_UBYTE Open_drain - Push pull or open drain selection modes 
* \return   void
*/

void HAL_led_Init_channel(T_UBYTE channel, T_UBYTE input_output, T_UBYTE Open_drain)
{
	IO_SetPinFctn(channel,PA_GPIO);                 /* GPIO */
	
    if (input_output == GPIO_OUTPUT)
    {    	
    	IO_SetPinAsOutput(channel);                 /* Output buffer enable */
    	IO_PinOpenDrainEnable(channel, Open_drain); /* Open drain option enable */	
    	
    }
    else if (input_output == GPIO_INPUT)
    {
    	IO_SetPinAsInput(channel);					/* Input buffer enable */	
    }

}

/****************************************************************************************************/
/**
* \brief    Initialize GPIO port connected to LEDs on eval board
* \author   Abraham Tezmol
* \param    void 
* \return   void
*/
void HAL_led_Init(void)
{
    /* Data Port A initialization */
	HAL_led_Init_channel(LED1,GPIO_OUTPUT,GPIO_OPEN_DRAIN_ENABLE);  /* PE4 --> LED1*/
	IO_PinWrite(LED1, LED_OFF); 
	HAL_led_Init_channel(LED2,GPIO_OUTPUT,GPIO_OPEN_DRAIN_ENABLE);  /* PE5 --> LED2*/
	IO_PinWrite(LED2, LED_OFF); 
	HAL_led_Init_channel(LED3,GPIO_OUTPUT,GPIO_OPEN_DRAIN_ENABLE);  /* PE6 --> LED3*/
	IO_PinWrite(LED3, LED_OFF); 
	HAL_led_Init_channel(LED4,GPIO_OUTPUT,GPIO_OPEN_DRAIN_ENABLE);  /* PE7 --> LED4*/
	IO_PinWrite(LED4, LED_OFF); 
	
}

/****************************************************************************************************/

void HAL_led_TurnOn(T_UBYTE led)
{
	IO_PinWrite(led, LED_ON);
}

void HAL_led_TurnOff(T_UBYTE led)
{
	IO_PinWrite(led, LED_OFF);
}

